//
//  MRMAlipayWithdrawViewController.m
//  MeiRiMoney
//
//  Created by qiuqk on 13-6-29.
//  Copyright (c) 2013年 MeiRiCai. All rights reserved.
//

#import "MRMAlipayWithdrawViewController.h"
#import "MRMUtils.h"
#import "MRMExchangeCompleteView.h"
#import "MRMSdk.h"

@interface MRMAlipayWithdrawViewController ()

@end

@implementation MRMAlipayWithdrawViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
	
	self.alipayTextField.delegate = self;
	self.nameTextField.delegate = self;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewDidUnload {
    [self setOkButton:nil];
	[self setAlipayTextField:nil];
	[self setNameTextField:nil];
    [super viewDidUnload];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
	[textField resignFirstResponder];
	return TRUE;
}

- (IBAction)okButton_TouchUpInside:(id)sender
{
	NSString *alipay = self.alipayTextField.text;
	NSString *name = self.nameTextField.text;
	
	if ([alipay isEqual: @""] || [name isEqual: @""])
	{
		UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"" message:@"请正确填写信息" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
		[alertView show];
		return;
	}
	
	NSString *msg = [NSString stringWithFormat:@"%@\n%@", alipay, name];
	
	UIAlertView *confirmView = [[UIAlertView alloc] initWithTitle:@"请确认支付宝账号信息" message:msg delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
	[confirmView show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
	if (buttonIndex == 1) {
		NSString *alipay = self.alipayTextField.text;
		NSString *name = self.nameTextField.text;
		NSString *shipAddress = [NSString stringWithFormat:@"%@,%@", alipay, name];
		NSLog(@"%@", shipAddress);
		
		[MRMSdk exchangeCommodity:self.commodity.Id number:1 shipAddress:shipAddress];
		
		[MRMUtils showExchangeCompleteView:self];
	}
}

@end
